package com.bdqn;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 饿汉模式
 * 读取配置文件
 */
public class ConfigManager2 {
    //在类加载时即创建ConfigManage实例
    private static ConfigManager2 configManager2 = new ConfigManager2();
    private static Properties properties;
    /**
     * 私有构造方法
     */
    private ConfigManager2(){
        String configFile = "database.properties";
        properties = new Properties();
        InputStream is = ConfigManager2.class.getClassLoader().getResourceAsStream(configFile);
        try{
            properties.load(is);
        }catch (IOException e){
            e.printStackTrace();
        }
    }

    //饿汉模式
    public static ConfigManager2 getInstance(){
        return configManager2;
    }
    public String getValue(String key){
        return properties.getProperty(key);
    }
}
